package xyz.robinbingo.effectivejava.chapter03.item10.other;
// Adds a value component without violating the equals contract

import xyz.robinbingo.effectivejava.chapter03.item10.Point;

import java.awt.*;
import java.util.Objects;

public class ColorPoint {
    private final Point point;
    private final Color color;

    public ColorPoint(int x, int y, Color color) {
        point = new Point(x, y);
        this.color = Objects.requireNonNull(color);
    }

    /**
     * Returns the point-view of this color point.
     *
     * @param
     * @return
     * @author Robin
     * @date 2019/3/22 13:47
     **/
    public Point asPoint() {
        return point;
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof ColorPoint))
            return false;
        ColorPoint cp = (ColorPoint) o;
        return cp.point.equals(point) && cp.color.equals(color);
    }
}